package linear_list.leetcode.medium;

/**
 * @author Stark
 * @description 链表中倒数第k个节点
 * 题目链接：https://leetcode-cn.com/problems/lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof
 * @date 2022/4/11 19:48
 **/
public class Offer22_GetKthFromEnd {
    public ListNode getKthFromEnd(ListNode head, int k) {
        ListNode slow = head,fast = head;
        while(k-- != 0)
            fast = fast.next;
        while(fast != null){
            slow = slow.next;
            fast = fast.next;
        }
        return slow;
    }
}
